// Fill out your copyright notice in the Description page of Project Settings.

#pragma once
#include "JsEnv.h"

#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "../DeclareDelegate.h"
#include "AnimSampleGameInstance.generated.h"


class FTSTickTask
{
public:
	FTSTickTask(class UAnimSampleGameInstance* InGameInstance): GameInstance(InGameInstance)
	{}
	static const TCHAR*GetTaskName()
	{
		return TEXT("FTSTickTask");
	}
	//Fixed writing, used for statistic
	FORCEINLINE static TStatId GetStatId()
	{
		RETURN_QUICK_DECLARE_CYCLE_STAT(FTSTickTask, STATGROUP_TaskGraphTasks);
	}
	/** return the thread for this task **/
	static ENamedThreads::Type GetDesiredThread()
	{
		return ENamedThreads::GameThread;
	}
	static ESubsequentsMode::Type GetSubsequentsMode()
	{
		return ESubsequentsMode::TrackSubsequents;
	}
	void DoTask(ENamedThreads::Type CurrentThread, const FGraphEventRef& MyCompletionGraphEvent)
	{
		if(GameInstance != nullptr) {}
	}
private:
	class UAnimSampleGameInstance* GameInstance = nullptr;
};
/**
 * 
 */
UCLASS()
class ANIMSAMPLE_API UAnimSampleGameInstance : public UGameInstance
{
	GENERATED_BODY()
public:

	virtual void Init() override;

	virtual void OnStart() override;

	virtual void Shutdown() override;

	//Used to tick ts script
	bool Tick(float DeltaTime);

	UFUNCTION()
	void RegisterInteractionScriptFunctionByName(UObject* Object, FString DelegateName, FString FunctionName);
	UPROPERTY()
	FNotifyRegisterInteractionFunction	NotifyRegisterInteractionFunction;
	UPROPERTY()
	FNotifyRegisterSelfDefinedTickFunction NotifyRegisterSelfDefinedTickFunction;
	TSharedPtr<puerts::FJsEnv> ClientGameScript;
	TSharedPtr<puerts::FJsEnv> ServerGameScript;
};
